package levelEditor;

import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

public class LevelFactoryWriter {
    
    public LevelFactoryWriter() {
    }
    
    public String guiTree2String(Node root) {
        StringBuilder result = new StringBuilder();
        bricks2String(result, root);
        return result.toString();
    }
    
    private void bricks2String(StringBuilder result, Node root) {
        Node brickRoot = (Node)root.getChild("bricks");
        if(brickRoot != null){
            result.append("TotalBricks:");
            result.append(brickRoot.getQuantity());
            result.append("\n\n");
            for(int i = 0; i<brickRoot.getQuantity();i++){
                brick2String(result, brickRoot.getChild(i), i);
            }
        }
    }
    
    private void brick2String(StringBuilder result, Spatial brick, int index) {
        result.append("Brick_");
        result.append(index);
        result.append("_Type:");
        result.append(brick.getName());
        result.append("\n");
        
        result.append("Brick_");
        result.append(index);
        result.append("_PosX:");
        result.append(brick.getLocalTranslation().x);
        result.append("\n");
 
        result.append("Brick_");
        result.append(index);
        result.append("_PosY:");
        result.append(brick.getLocalTranslation().y);
        result.append("\n");
    }
}
